<template>
  <div class="card">
    <!-- 头像 -->
    <div class="avatar">
      <img src="https://picsum.photos/100/100" alt="头像" @click="goToPublisherDetail(publisherName)">
    </div>
    <!-- 标题 -->
    <div class="title">{{publisherName}}</div>
    <!-- 口号 -->
    <div class="slogan">{{userProfile}}</div>
    <!-- 数据 -->
    <div class="data-container">
      <div class="data-item">
        <div class="data-value">{{userArticles}}</div>
        <div class="data-label">文章数</div>
      </div>
      <div class="data-item">
        <div class="data-value">{{userFans}}</div>
        <div class="data-label">粉丝数</div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'PublisherInfo',
  props: {
    publisherName: {
      type: [String, Number],
      default: '未知用户'
    },
    userFans: {
      type: [String, Number],
      default: 0
    },
    userArticles: {
      type: [String, Number],
      default: 0 
    },
    userProfile: {
      type: [String, Number],
      default: '' 
    }
  },
  methods: {
    goToPublisherDetail(publisherName) {
      
      if (!this.$store.state.user.isLogin) {
        this.$centerMessage({
          message: '请先登录' + "\u00A0\u00A0\u00A0",
          type: 'error'
        });
        return
      }
      

      try {
        // console.log(publisherName);
        this.$router.replace({
          name: 'publisher',
          params: { publisherName },
        });
      } catch (err) {
        if (err.name !== 'NavigationDuplicated') {
          console.error('导航失败:', err);
        }
      }
    }
  }
}
</script>

<style scoped>
.card {
  background-color: white;
  margin-top: 30px;
  /* padding: 20px; */
  /* border-radius: 8px; */
  /* box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); */
  width: 300px;
  text-align: center;
  position: relative;
}

.avatar {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background-color: #e0e0e0; /* 头像背景色 */
  margin: 0 auto 15px; /* 居中并留出下方间距 */
  overflow: hidden;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover; /* 确保图片填充 */
}

.title {
  font-size: 24px;
  font-weight: bold;
  color: #333;
  margin-bottom: 10px;
}

.slogan {
  font-size: 14px;
  color: #666;
  margin-bottom: 20px;
}

.data-container {
  display: flex;
  justify-content: space-between;
}

.data-item {
  text-align: center;
}

.data-value {
  font-size: 20px;
  font-weight: bold;
  color: #e74c3c;
}

.data-label {
  font-size: 14px;
  color: #666;
}
</style>